package plugins.lxfa.No3.view
{
    import br.com.stimuli.loading.*;
    
    import core.manager.*;
    import core.manager.playerManager.flvPlayerManager.*;
    
    import flash.events.*;
    import flash.ui.ContextMenu;
    
    import memory.*;
    
    import mx.core.*;
    
    import plugins.lxfa.animatePlayer.*;
    
    import view.loadings.*;

    public class No3Base extends UIComponent
    {
        private var loading_mc:LoadingWaveRota;
        private var loader:BulkLoader;
        private var isClosed:Boolean = false;

        public function No3Base()
        {
            MainSystem.getInstance().isBusy = true;
            initAnimatePlayer();
            return;
        }// end function

        private function initFLVPlayer() : void
        {
            FlvPlayerManager.getInstance().showFlvById("second");
            var menu:ContextMenu=new ContextMenu();
            menu.hideBuiltInItems();
            Application.application.contextMenu=menu;
            menu.addEventListener(ContextMenuEvent.MENU_SELECT,function(e:ContextMenuEvent):void
            {
            	AnimatePlayer.getInstance().removeAnimate();
            });
            return;
        }// end function

        private function initLoadingMc() : void
        {
            loading_mc = new LoadingWaveRota();
            this.addEventListener(Event.ADDED_TO_STAGE, on_added_to_stage);
            return;
        }// end function

        private function on_all_loaded(getFailedItems:BulkProgressEvent) : void
        {
            AnimatePlayer.getInstance().init();
            initFLVPlayer();
            loader.clear();
            loader.removeAll();
            loader = null;
            if (loading_mc != null)
            {
                if (loading_mc.parent != null)
                {
                    loading_mc.parent.removeChild(loading_mc);
                }
                loading_mc = null;
            }
            MainSystem.getInstance().isBusy = false;
            return;
        }// end function

        private function on_added_to_stage(getFailedItems:Event) : void
        {
            loading_mc.x = this.stage.stageWidth / 2;
            loading_mc.y = this.stage.stageHeight / 2;
            Application.application.addChildAt(loading_mc, Application.application.numChildren-1);
            return;
        }// end function

        private function on_progress(getFailedItems:BulkProgressEvent) : void
        {
            loading_mc.updateByProgressEvent(getFailedItems);
            return;
        }// end function

        private function initAnimatePlayer() : void
        {
            initLoadingMc();
            loader = new BulkLoader("hello");
            loader.add("swf/animate/animate.swf");
            loader.add("plugins/lxfa/mainMenuBottom/MainMenuBottomModule.swf");
            loader.add("plugins/lxfa/mainMenuTop/MainMenuTopModule.swf");
            loader.add("http://audio.pavilion.expo.cn/p5006/audio/animate/out.mp3");
            loader.start();
            loader.addEventListener(BulkProgressEvent.PROGRESS, on_progress);
            loader.addEventListener(BulkProgressEvent.COMPLETE, on_all_loaded);
            return;
        }// end function

        public function dispose() : void
        {
            MemoryRecovery.getInstance().gcFun(loader, BulkProgressEvent.PROGRESS, on_progress);
            MemoryRecovery.getInstance().gcFun(loader, BulkProgressEvent.COMPLETE, on_all_loaded);
            if (loading_mc != null)
            {
                if (loading_mc.parent != null)
                {
                    loading_mc.parent.removeChild(loading_mc);
                }
                loading_mc = null;
            }
            MemoryRecovery.getInstance().gcFun(this, Event.ADDED_TO_STAGE, on_added_to_stage);
            FlvPlayerManager.getInstance().removeFlvById("second");
            AnimatePlayer.getInstance().removeAnimate();
            return;
        }// end function

    }
}
